home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS13.ADF / FutureSound / loadsound.c < prev    next >
C/C++ Source or Header  |  1986-08-05  |  2KB  |  76 lines

  1. /* LoadSound.c */
  2.  
  3. /* This routine will load a soundfile from disk, */
  4. /* provided that the file was saved in either */
  5. /* IFF or FutureSound format, and resides in the */
  6. /* current default directory. */
  7.  
  8. /* Usage : LoadFile(filename,buffer) */
  9. /* filename is a pointer to a string */
  10. /* buffer is a pointer (char *) to an allocated memory area */
  11. /* return value : record rate (UWORD) */
  12.  
  13. /* converted to use AmigaDOS I/O calls, John Foust, 6/22/86 */
  14.  
  15. #include "exec/types.h"         /* Amiga typedefs */
  16. #include "lattice/stdio.h"         /* Lattice I/O defs */
  17. #include "SoundErrors.h"         /* FutureSound aux routine error codes */
  18.  
  19. #include "libraries/dosextens.h"
  20.  
  21. extern struct FileHandle *Open();
  22.  
  23. extern UWORD ReadIFF();         /* IFF file reader (returns rec rate) */
  24. extern ULONG SizeIFF();         /* returns size of IFF data */
  25.  
  26. UWORD LoadSound(filename,buffer)         /* Read SoundFile */
  27. char *filename,*buffer;
  28. {
  29. /* FILE *fd; */
  30. struct FileHandle *fp;               /* File Pointer */
  31.    ULONG len;                        /* Data Length */
  32.    UWORD rec_rate;                   /* Record Rate (kHz) */
  33.  
  34.    /* Is it an IFF File? */
  35.    if((len=SizeIFF(filename)) != 0)
  36.    {
  37.       /* Yes, then read in IFF format */
  38.       return(ReadIFF(filename,buffer));
  39.    }
  40.    else
  41.    {
  42.       /* No, then read in FutureSound format */
  43.  
  44.       /* Open file for reading */
  45.       if((fp = Open(filename,MODE_OLDFILE)) == 0)
  46.       {
  47.          return(Error(OPEN_ERROR,filename));
  48.       }
  49.  
  50.       /* Read length of data */
  51.       if(Read(fp,&len,sizeof(len))==0)
  52.       {
  53.          return(Error(READ_ERROR,filename));
  54.       }
  55.  
  56.       /* Read record rate */
  57.       if(Read(fp,&rec_rate,sizeof(rec_rate)) == 0)
  58.       {
  59.          return(Error(READ_ERROR,filename));
  60.       }
  61.  
  62.       /* Read data into buffer */
  63.       if(Read(fp,buffer,len) == 0)
  64.       {
  65.          return(Error(READ_ERROR,filename));
  66.       }
  67.  
  68.       /* Close file */
  69.       Close(fp);
  70.  
  71.       /* Return record rate if file was successfully read */
  72.       return(rec_rate);
  73.    }
  74. }
  75.  
  76.